package com.briup.jz.web.controller;

import com.briup.jz.bean.Product;
import com.briup.jz.service.IProductService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
@Api(description="产品信息")
public class ProductController {
    @Autowired
    private IProductService iProductService;
    @ApiOperation("查询产品信息")
    @GetMapping("/query")
    public Message query(Long id){
        List<Product> products = iProductService.query(id);
        return MessageUtil.success(products);
    }
    @ApiOperation("保存或更新产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name" ,value = "产品名称", paramType = "form"),
            @ApiImplicitParam(name = "description" ,value = "描述信息", paramType = "form"),
            @ApiImplicitParam(name = "price" ,value = "价格", paramType = "form"),
            @ApiImplicitParam(name = "status" ,value = "状态", paramType = "form"),
            @ApiImplicitParam(name = "photo" ,value = "图片", paramType = "form"),
            @ApiImplicitParam(name = "productCategoryId" ,value = "产品分类id", paramType = "form"),

    })
    @PostMapping("saveorupdate")
    public  Message saveOrUpdate(Product product){
        iProductService.saveOrUpdate(product);
        return  MessageUtil.success("操作成功");
    }
    @ApiOperation("通过id删除")
    @GetMapping("delete")
    @ApiImplicitParam(name = "id" ,required = true,value = "产品编号", paramType = "query" )
    public Message delete(Long id){
        iProductService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
    @GetMapping("/offline")
    @ApiOperation("产品下架")
    @ApiImplicitParam(name = "id" ,required = true,value = "产品编号", paramType = "query" )
    public Message offline(Long id){
     iProductService.offline(id);
     return  MessageUtil.success("操作成功");
    }
    @GetMapping("/online")
    @ApiOperation("产品上架")
    @ApiImplicitParam(name = "id" ,value = "产品编号",required = true, paramType = "query")
    public Message online(Long id){
        iProductService.online(id);
        return  MessageUtil.success("操作成功");
    }
}
